package com.superhelp.ebill.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.superhelp.ebill.model.User;


/**
 * 用户信息存储
 * 
 *
 */
public class UserPrefUtils {

	private static final String USERPRENAME = "my_user_pref";

	private SharedPreferences userPref;

	private Editor userEditor;


	public UserPrefUtils(Context mContext) {
		userPref = mContext.getSharedPreferences(USERPRENAME,
				Context.MODE_PRIVATE);
		userEditor = userPref.edit();
	}

	/**
	 * 保存用户,传空的时候相当于对用户信息进行清除
	 * 
	 * @param user
	 */
	public void saveUser(User user) {
		// 空的时候相当于清除操作
		if (null == user) {
			boolean isGuide = userPref.getBoolean("guide", true);
			userEditor.clear();
			userEditor.putBoolean("guide", isGuide);
			userEditor.commit();
		} else {

//			userEditor.putString("gzno", user.getGzno());
		}

		userEditor.commit();
	}
	public void savetoken(String token) {
		userEditor.putString("token", token);
		userEditor.commit();
	}
	/**
	 * 获取用户
	 * 
	 * @return
	 */
	public User getUser() {
		User user = new User();

//		user.setGzno(userPref.getString("gzno", ""));
		return user;
	}
	
	public String getPSW() {
		return userPref.getString("psw", "");
	}

	public void savePSW(String psw) {
		userEditor.putString("psw", psw);
		userEditor.commit();
	}

}
